Skip to content

Fix gateway launchd log growth#921

Closed
wuman001 wants to merge 1 commit into
mainfrom
fix/gateway-launchd-log-growth
Closed

Fix gateway launchd log growth#921
wuman001 wants to merge 1 commit into
mainfrom
fix/gateway-launchd-log-growth

Conversation

@wuman001

Copy link
Copy Markdown
Collaborator

Summary

  • Suppress high-volume gateway/AWorld console logs from launchd stderr by default while keeping rotating gateway file logs.
  • Downgrade successful WeChat getupdates polling logs from INFO to DEBUG.
  • Add a launchd wrapper script that rotates stdout/stderr logs before starting aworld-gateway.

Test Plan

  • python -m py_compile aworld-cli/src/aworld_cli/gateway_cli.py aworld_gateway/logging.py aworld_gateway/channels/wechat/connector.py
  • bash -n scripts/run-aworld-gateway.sh
  • PYTHONPATH=aworld-cli/src pytest tests/gateway/test_gateway_status_command.py tests/gateway/test_wechat_connector.py tests/test_gateway_cli.py -q

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces improved logging controls for the gateway, including suppressing console logging by default, dynamically setting logger propagation based on environment variables, and reducing WeChat API polling log noise by logging updates at the debug level. It also adds a startup script with log rotation capabilities and corresponding tests. The review feedback suggests simplifying the platform-specific file size check in the shell script, moving the console logging suppression inside the try block to guarantee environment variable restoration, and adding a missing assertion in the logging configuration tests.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +11 to +18
file_size_bytes() {
local file="$1"
if stat -f %z "$file" >/dev/null 2>&1; then
stat -f %z "$file"
return
fi
stat -c %s "$file"
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The file_size_bytes function can be simplified and optimized to avoid running stat twice on macOS/BSD systems. By using the || operator, we can attempt the macOS/BSD-specific stat command and fall back to the Linux-specific one in a single line, which is also fully compatible with set -e.

Suggested change
file_size_bytes() {
local file="$1"
if stat -f %z "$file" >/dev/null 2>&1; then
stat -f %z "$file"
return
fi
stat -c %s "$file"
}
file_size_bytes() {
local file="$1"
stat -f %z "$file" 2>/dev/null || stat -c %s "$file"
}

Comment on lines +284 to +289
previous_disable_console_log = os.environ.get("AWORLD_DISABLE_CONSOLE_LOG")
previous_gateway_console_log = os.environ.get(GATEWAY_CONSOLE_LOG_ENV)
gateway_log_path: Path | None = None
_suppress_gateway_console_logging()
try:
await server.serve()
gateway_log_path = _configure_gateway_file_logging(base_dir=resolved_base_dir)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To ensure robust environment variable restoration, _suppress_gateway_console_logging() should be called inside the try block. If an exception (such as a KeyboardInterrupt or other asynchronous exception) occurs after _suppress_gateway_console_logging() is called but before entering the try block, the environment variables will not be restored in the finally block.

Suggested change
previous_disable_console_log = os.environ.get("AWORLD_DISABLE_CONSOLE_LOG")
previous_gateway_console_log = os.environ.get(GATEWAY_CONSOLE_LOG_ENV)
gateway_log_path: Path | None = None
_suppress_gateway_console_logging()
try:
await server.serve()
gateway_log_path = _configure_gateway_file_logging(base_dir=resolved_base_dir)
previous_disable_console_log = os.environ.get("AWORLD_DISABLE_CONSOLE_LOG")
previous_gateway_console_log = os.environ.get(GATEWAY_CONSOLE_LOG_ENV)
gateway_log_path: Path | None = None
try:
_suppress_gateway_console_logging()
gateway_log_path = _configure_gateway_file_logging(base_dir=resolved_base_dir)

Comment on lines +110 to +111
monkeypatch.setenv("AWORLD_GATEWAY_CONSOLE_LOG", "true")
gateway_cli._configure_gateway_file_logging(base_dir=tmp_path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test test_configure_gateway_file_logging_can_suppress_console_propagation sets AWORLD_GATEWAY_CONSOLE_LOG to "true" and calls _configure_gateway_file_logging, but it misses the assertion to verify that propagate is indeed set to True.

Suggested change
monkeypatch.setenv("AWORLD_GATEWAY_CONSOLE_LOG", "true")
gateway_cli._configure_gateway_file_logging(base_dir=tmp_path)
monkeypatch.setenv("AWORLD_GATEWAY_CONSOLE_LOG", "true")
gateway_cli._configure_gateway_file_logging(base_dir=tmp_path)
assert logging.getLogger("aworld.gateway").propagate is True

@wuman001

Copy link
Copy Markdown
Collaborator Author

Closing this PR because it included scripts/run-aworld-gateway.sh. Replacing it with a clean branch that removes that file from the PR diff.

@wuman001 wuman001 closed this Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant